<%@ Page Language="C#" MasterPageFile="~/FiledbookMaster.Master" AutoEventWireup="true" CodeBehind="FieldList.aspx.cs" Inherits="Fieldbook.Testwebsite.User.FieldList" Title="Untitled Page"%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        function ShowHideDiv(on, elemID)
        {
            var divElem = document.getElementById(elemID);
            if (on)
            {
                divElem.style.display = "block";
            }
            else 
            {
                divElem.style.display = "none";
            }
            return false;
        }
        
        var coordsSetting = false;
        function clickEvent()
        {
            /*
            alert(window.event.offsetX);
            alert(window.event.offsetY);
            */
            /*
            var hImage = document.getElementById('vojaimg');
            hImage.style.position = "absolute";
            hImage.style.left = window.event.clientX;
            hImage.style.top = window.event.clientY;
            */
            coordsSetting = false;
        }
        
        function mouseOverEvent()
        {
            if (coordsSetting)
            {
                var hImage = document.getElementById('vojaimg');
                var txtXCoor = document.getElementById('<%= this.txtFieldMapX.ClientID %>');
                var txtYCoor = document.getElementById('<%= this.txtFieldMapY.ClientID %>');
                var x = window.event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                var y = window.event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
                txtXCoor.value = x; // this is absolute, find relative coords to the picture
                txtYCoor.value = y; // this the absolute, find relative coords to the picture
                hImage.style.left = x; // window.event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                hImage.style.top = y; // window.event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
            }               
        }
        
        function startSettingCords()
        {
            coordsSetting = true;
            return false;
        }
        
        function changeMap(mapID)
        {
            var map = document.getElementById('fieldmap');
            map.src = 'GenerateMap.axd?userID=69&mapID=' + mapID;
            return false;
        }
        
    </script>
    <a href="#" onclick="return ShowHideDiv(true, 'divAddField')">Add field</a>
    <br />
    <br />
    <asp:Label ID="lblOperationStatus" runat="server" EnableViewState="false"/>
    <div id="divAddField" style="display:none">
        <table>
            <tr>
                <td>Cataster: </td>
                <td>
                    <asp:TextBox runat="server" ID="txtCataster"/>
                </td>
            </tr>
            <tr>
                <td>Owner: </td>
                <td>
                     <asp:DropDownList runat="server" ID="ddlOwner" />
                </td>
            </tr>
            <tr>
                <td>Measure unit: </td>
                <td>
                     <asp:DropDownList runat="server" ID="ddlMeasureUnits"/>
                </td>
            </tr>
            <tr>
                <td>Area: </td>
                <td>
                    <asp:TextBox ID="txtArea" runat="Server" CssClass="txtnumber"/>
                </td>
            </tr>
            <tr>
                <td>Field map: </td>
                <td>
                    <select id="selectOperationCategory" runat="server"
                        datasourceid="UserMapsODS"
                        datavaluefield="FieldMapID"
                        datatextfield="Description"
                        onchange="changeMap(this.options[this.selectedIndex].value);">
                    </select>
                </td>
            </tr>
            <tr>
                <td>X coordinate:</td>
                <td>
                    <asp:TextBox ID="txtFieldMapX" runat="Server" CssClass="txtnumber" />
                </td>
            </tr>
            <tr>
                <td>Y coordinate:</td>
                <td>
                    <asp:TextBox ID="txtFieldMapY" runat="Server" CssClass="txtnumber" />
                </td>
            </tr>
            <tr>
                <td>
                <a href="#" onclick="return startSettingCords();">
                    Set coordinates
                </a>
                </td>
                <td>
                    <asp:LinkButton runat="server" ID="Add" Text="Add field" OnCommand="AddField_Command"  />
                    <a href="#" onclick="return ShowHideDiv(false, 'divAddField')">Cancel</a>                        
                </td>
            </tr>
        </table>
    </div>    
    <asp:GridView ID="dgvFields" runat="server" AutoGenerateColumns="false" 
                DataSourceID="FieldsODS" 
                DataKeyNames="FieldID"
                OnRowDataBound="dgvFields_RowDataBound">
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="Cataster" HeaderText="Cataster" SortExpression="Cataster"/>
        <asp:TemplateField>
            <HeaderTemplate>
                Owner
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label runat="Server" ID="OwnerID" Text='<%# Eval("OwnerID") %>'/>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Area" HeaderText="Area" SortExpression="Area" />
        <asp:TemplateField>
            <HeaderTemplate>
                MeasureUnit
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label runat="server" ID="lblMeasureUnit" Text='<%# Bind("MeasureUnitID") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="FieldStateID" HeaderText="FieldStateID" SortExpression="FieldStateID" />
        <asp:TemplateField>
            <HeaderTemplate>
                Current specie
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label runat="server" ID="lblFieldID" Text='<%# Bind("FieldID") %>'></asp:Label>
                <asp:LinkButton runat="server" ID="linkShowCulturesHistory" PostBackUrl='<%# Bind("FieldID", "~/User/FieldSpecies.aspx?fieldID={0}") %>'>Show history</asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    </asp:GridView>
    <br />
    <asp:GridView ID="dgvFieldWorks" runat="server" AutoGenerateColumns="false" 
        AllowPaging="True"
        DataSourceID="FieldWorksODS"
        OnRowDataBound="dgvFieldWorks_RowDataBound">
        <Columns>
            <asp:TemplateField>
                <HeaderTemplate>
                    Executor
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:Label runat="Server" ID="ExecutorID" Text='<%# Eval("ExecutorID") %>'/>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="ExecutionDate" HeaderText="ExecutionDate" SortExpression="ExecutionDate" DataFormatString="{0: dd/MM/yyyy}"/>
            <asp:BoundField DataField="TotalCost" HeaderText="TotalCost" SortExpression="TotalCost"/>
            <asp:BoundField DataField="Remarks" HeaderText="Remarks" SortExpression="Remarks"/>
        </Columns>
    </asp:GridView>
    <img src="GenerateMap.axd?userID=69&mapID=1" width="860px" height="480px" id='fieldmap'
        usemap="#fieldMap" 
        onclick="clickEvent();"
        onmousemove="mouseOverEvent();"/>
    <map name="fieldMap">
        <area shape="circle" coords="100, 100, 50" href="#" alt="test" onclick="alert('nije voja');"/>
    </map>
    <img src="../FieldMaps/flag_green.gif" id="vojaimg" style="position:absolute; left:-100px; top:-100px;"/>
    <asp:ObjectDataSource ID="FieldsODS" runat="server" TypeName="Fieldbook.Business.FieldController"
        SelectMethod="LoadHouseHoldFields">
        <SelectParameters>
            <asp:SessionParameter Name="userID" SessionField="userID" Type="int64" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="UserMapsODS" runat="server" TypeName="Fieldbook.Business.FieldController"
        SelectMethod="LoadHouseHoldFieldMaps">
        <SelectParameters>
            <asp:SessionParameter Name="userID" SessionField="userID" Type="int64" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="FieldWorksODS" runat="server" TypeName="Fieldbook.Business.FieldController"
        SelectMethod="LoadFiledWorks"
        SelectCountMethod="GetFieldWorkCount" EnablePaging="True">
        <SelectParameters>
            <asp:ControlParameter Name="fieldID" Type="Int64" ControlID="dgvFields" PropertyName="SelectedValue"/>
            <asp:Parameter Name="maximumRows" Type="Int32" DefaultValue="7" />
            <asp:Parameter Name="startRowIndex" Type="Int32" DefaultValue="0" />
        </SelectParameters>
    </asp:ObjectDataSource>    
</asp:Content>
